import logging

from selenium.webdriver.common.by import By

from pageobj import BasePage
from settings import host

logger = logging.getLogger(__name__)


class DressPage(BasePage):
    """婚礼礼服详情页"""

    url = host + '/wedding-dresses'

    # 商品名称
    dressName = (By.CSS_SELECTOR, 'div.c_name a')
    # 商品数量
    inputCount = (By.CSS_SELECTOR, '.qty')
    # 加入购物车
    addProductToCartBtn = (By.CSS_SELECTOR, '.addProductToCart')

    def add_product2cart(self, count: int):
        """访问商品详情页并添加商品到购物车

        :param count:
        :return:
        """
        logger.info('开始添加商品到购物车')
        logger.debug('1.访问婚礼礼服列表页')
        self.open(self.url)
        logger.debug('2.点击某个商品进入商品详情页')
        self.click(self.dressName)
        logger.debug('# 3.输入商品数量')
        self.input(self.inputCount, count)
        logger.debug('4.点击"加入购物车"')
        self.click(self.addProductToCartBtn)
        logger.debug('# 5.等待跳转到购物车页面')
        self.url_changes(self.url)
